package view.toolboxComponents;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import controller.CustomEvent;
import controller.EventHandler;
import controller.ToolBoxEventHandler;
/** * A class for the encapsulation of the line width panel on the designer * @author Daniel Bond, Mohammed Abdullah, Gideon Pyzer * */
@SuppressWarnings("serial")
public class PrescriptionLineWidthPanel extends AbstractPanel{
	private JLabel lblLineWidth;
	private JComboBox cmbLineWidth;
	private EventHandler eventHandler;
	public PrescriptionLineWidthPanel(){
		super();
		cmbLineWidth = new JComboBox();		//TODO: perhaps put the below code into a function
		//Properties for ComboBoxes
		cmbLineWidth.addItem(0f);
		cmbLineWidth.addItem(1f);
		cmbLineWidth.addItem(2f);
		cmbLineWidth.addItem(3f);
		cmbLineWidth.addItem(4f);
		cmbLineWidth.addItem(5f);
		cmbLineWidth.addItem(6f);
		cmbLineWidth.addItem(7f);
		cmbLineWidth.addItem(8f);
		cmbLineWidth.addItem(9f);
		cmbLineWidth.addItem(10f);
		cmbLineWidth.setEditable(false);
		cmbLineWidth.setToolTipText("Line width of object");
		cmbLineWidth.setSelectedIndex(1);
		lblLineWidth = new JLabel("Line Width");
		//This combobox has the different line widths
		cmbLineWidth.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("presLineWidthChange", this, cmbLineWidth.getSelectedItem());
				PrescriptionLineWidthPanel.this.eventHandler = new ToolBoxEventHandler();
				PrescriptionLineWidthPanel.this.eventHandler.createEvent(event);	
			}
		});
		buildPanel();	
	}
	/**
	 * Set the selected line width property
	 * @param selected index
	 */
	public void setSelected(float selected){
		cmbLineWidth.setSelectedIndex((int)selected);
	}
	/**
	 * Build prescription name panel
	 */
	private void buildPanel(){
		this.add(lblLineWidth);
		makeRigidArea();
		this.add(cmbLineWidth);
	}	
	@Override
	public void resetComponent() {
		cmbLineWidth.setSelectedIndex(0);
	}
}